package com.syn.synold4s.control.dialog;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.gaoyi.basemodule.basedialog.BaseFragmentDialog;
import com.syn.synold4s.R;
import com.syn.synold4s.adapter.AlertAdapter;
import com.syn.synold4s.bean.dto.MapAllDeviceDto;
import com.syn.synold4s.databinding.WatchDialogBinding;

public class GoogleMapWatchDialog extends BaseFragmentDialog<WatchDialogBinding> {

    private MapAllDeviceDto data;
    private AlertAdapter alertAdapter;

    public GoogleMapWatchDialog(Context context, MapAllDeviceDto data) {
        super(context);
        this.data = data;
    }

    @Override
    protected void initView() {
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        mBinding.ivClose.setOnClickListener(view -> dismiss());
        setData();
    }

    private void setData() {
        if (data == null) return;
        alertAdapter = new AlertAdapter(mContext);
        mBinding.rv.setLayoutManager(new LinearLayoutManager(mContext));
        mBinding.rv.setAdapter(alertAdapter);
        mBinding.rv.setItemAnimator(null);
        if (data.getAlertEvent() != null && data.getAlertEvent().size() > 0) {
            mBinding.newDynamicLayout.setVisibility(View.VISIBLE);
            alertAdapter.submitList(data.getAlertEvent());
        }
        mBinding.tvStateName.setText(data.getStateName());
        Drawable mDrawable = ContextCompat.getDrawable(mContext, R.drawable.oval_yellow_bg);
        if (mDrawable != null) {
            mDrawable.setBounds(0, 0, mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight());
        }
        mBinding.tvStateName.setCompoundDrawablesRelative(mDrawable, null, null, null);
        mBinding.tvStateName.setTextColor(getResources().getColor(R.color.color_main));
        mBinding.tvRate.setText(data.getHeartRate() + "");
        mBinding.tvTemperature.setText(data.getTemperature() + "");
        mBinding.tvStaffName.setText(mContext.getString(R.string.wearer, data.getDeviceName()));
        mBinding.tvImei.setText("IMEI:" + data.getSn());
        mBinding.tvWatchType.setText(getString(R.string.watch_type) + (data.getDeviceType() != null && data.getDeviceType().getName() != null ? data.getDeviceType().getName() : ""));
        mBinding.tvAddress.setText(String.format(getString(R.string.address), data.getAddress()));
    }

    @Override
    protected WatchDialogBinding getViewBinding() {
        return WatchDialogBinding.inflate(getLayoutInflater());
    }

    @Override
    protected String getShowTag() {
        return BOTTOM;
    }
}
